using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using BO.Admin;
using BO;

namespace Admin.Controls.News
{
    public partial class ListPhoto : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //if (!IsPostBack)
            {
                BindData();
                ltrTextBox.Text = txtPhotoPath.ClientID;
                ltrWindow.Text = ExplorerWindow1.ClientID;
            }
        }

        private void BindData()
        {
            rptListPhoto.DataSource = null;
            rptListPhoto.DataSource = Image_Helper.GetByNewsID(Utils.QueryString.GetNewsID());
            rptListPhoto.DataBind();
        }

        protected void btAddPhoto_Clicked(object sender, EventArgs e)
        {
            if (txtPhotoPath.Text.Length > 0)
            {
                Image_Helper.Add(txtPhotoPath.Text, Utils.QueryString.GetNewsID());
                txtPhotoPath.Text = "";
                BindData();
            }
        }

        protected void btDelete_Commanded(object sender, CommandEventArgs e)
        {
            int imageid = 0;
            try
            {
                imageid = Convert.ToInt32(e.CommandArgument);
            }
            catch { }
            if (imageid > 0)
            {
                Image_Helper.Delete(imageid);
            }
            BindData();
        }
    }
}